package com.bruce.demo2.patterns.demo2.structural.demo10.facade;

/**
 * @PROJECT_NAME: design_patterns
 * @DESCRIPTION: 智能音箱
 * @AUTHOR: CNBruceLee
 * @DATE: 2021/7/28 7:00
 */
public class SmartApplicationsFacade {
    private Light light;
    private TV tv;
    private AirCondition airCondition;

    public SmartApplicationsFacade(Light light, TV tv, AirCondition airCondition) {
        this.light = light;
        this.tv = tv;
        this.airCondition = airCondition;
    }

    /**
     * 统一的访问入口 可以针对每一个电器进行控制
     *
     * @param message
     */
    public void say(String message) {
        if (message.contains("打开")) {
            on();
        } else if (message.contains("关闭")) {
            off();
        } else {
            throw new RuntimeException("未明白意思，还未学习的技能");
        }
    }

    /**
     * 打开
     */
    private void on() {
        light.on();
        tv.on();
        airCondition.on();
    }

    /**
     * 关闭
     */
    private void off() {
        light.off();
        tv.off();
        airCondition.off();
    }
}
